<template>
    <div>
        <!-- search start -->
        <searchBar
                placeHolder="请输入市代名称/负责人名称"
                @handleSearch="init"
        />
        <!-- search end -->

        <!-- table start -->
        <tableDataEl
                :page.sync="page"
                :pageSize.sync="pageSize"
                :tableData="tableData.list"
                :tableLabel="tableLabel"
                :pageCount="tableData.rows"
                v-loading="loading"
                @handleDetail="handleDetail"
        />
        <!-- table end -->

        <!-- dialog start -->
        <el-dialog
                :visible.sync="isShowDialog"
                center
                width="40%"
                title="物料详情"
                v-el-drag-dialog
        >
            <el-form v-loading="detailLoading">
                <el-form-item label="物料信息:">
                    <el-table :data="mate" border>
                        <el-table-column
                                label="物料名称"
                                prop="materiel"
                                align="center"
                        >

                        </el-table-column>
                        <el-table-column
                                label="数量"
                                prop="num"
                                align="center"
                        >

                        </el-table-column>
                        <el-table-column
                                label="备注"
                                prop="remarks"
                                align="center"
                        >

                        </el-table-column>
                    </el-table>
                </el-form-item>
                <el-form-item label="收货地址:">
                    {{address.province}}{{address.city}}{{address.county}}{{address.address}}
                </el-form-item>
            </el-form>
        </el-dialog>
        <!-- dialog end -->
    </div>
</template>

<script>
    import tableDataEl from '@/views/Setup/common/table'
    export default {
        name: "material",
        components: {
            tableDataEl
        },
        data () {
            return {
                page: 1,
                pageSize: 8,
                tableData: {},
                tableLabel: [
                    {
                        label: '市代名称',
                        prop: 'company'
                    },
                    {
                        label: '负责人',
                        prop: 'leader'
                    },
                    {
                        label: '联系方式',
                        prop: 'phone'
                    },
                    {
                        label: '申请时间',
                        prop: 'create_time'
                    },
                    {
                        label: '详情',
                        detail: true,
                        btnText: '查看',
                        methodName: 'handleDetail'
                    },
                    {
                        label: '审核时间',
                        prop: 'audit_time'
                    },
                    {
                        label: '审核人',
                        prop: 'audit_person'
                    }
                ],
                loading: false,
                isShowDialog: false,
                detailLoading: false,
                mate: [],
                address: {},
                isShowReject: false,
                rejectText: {
                    text: ''
                },
                obj: {}
            }
        },
        methods: {
            async init ( search = '' ) {  //初始化
                if( search ) search['key'] = search['search'];
                this.loading = true;
                let paramsStr = Object.assign(search, {page: this.page, pageSize: this.pageSize});
                let res = await this.api.lot_passList(paramsStr);
                res.code ? this.tableData = res.data : this.$message(res.msg);
                this.loading = false
            },
            async handleDetail ( ...value ) { //详情
                this.isShowDialog = true;
                this.detailLoading = true;
                const temp = value[1];
                let res = await this.api.getMateDetail({id: temp['id'], gid: temp['gid']});
                if( res.code ) {this.mate = res.data.mate; this.address = res.data.address; }
                else this.$message(res.msg);
                this.detailLoading = false;
            },
        },
        mounted () {
            this.init();
        },
        watch: {
            page () {
                this.init();
            },
            pageSize () {
                this.init();
            }
        }
    }
</script>

<style scoped>

</style>
